var postMoudle = {

	data: {
		posts: null
	},
	open: false,
	loading: function(render) {
		var that = this.data;
		if(!this.open) {
			$.ajax({
				url:'https://www.maksdu.com/app/post/all',
				method: 'get',
				success: function(data) {

					if(data.result.code == 200) {
						that.posts = data.result.value;
						that.open = true;
						render(that.posts);
					}
				}
			})
		}
	},
	loaded: function(render) {
		if(this.data.posts == null) {
			this.loading(render);
		}
		return render(this.data.posts);
	},
	reset: function() {
		this.data.posts = null;
	}

}
var categoryMoudle = {

	data: {
		categorys: null
	},
	open: false,
	loading: function() {
		var that = this;
		if(!this.open) {
			$.ajax({
				url:'https://www.maksdu.com/app/category/all',
				method: 'get',
				success: function(data) {
					if(data.code == 200) {
						that.data.categorys = data.result.value;
						that.open = true;
						that.render(that.data.categorys);
					}
				}
			})
		}
	},
	loaded: function() {
		if(this.data.categorys == null) {
			this.loading();
		}
		return this.render(this.data.categorys);
	},
	reset: function() {
		this.data.categorys = null;
	},
	render: function(data) {
		if(data) {
			var index = 4;
			data.forEach(function(element){
				$("#nav_"+index).html(element.categoryName);
				index--;
			})
		}
	}

}
